﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Views/Game/GameView.Master"%>
<%@ Import Namespace="Heritage.Codebox" %>
<%@ Import Namespace="Heritage" %>
<%@ Import Namespace="Heritage.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% GameMessages model = ViewData.Model as GameMessages;
   string str = model.MessageText.Replace("\n", "<br>");    
%>
<script type="text/javascript">
    function setCursor(el, st, end) {
        if (el.setSelectionRange) {
            el.focus();
            el.setSelectionRange(st, end);
        }
        else {
            if (el.createTextRange) {
                range = el.createTextRange();
                range.collapse(true);
                range.moveEnd('character', end);
                range.moveStart('character', st);
                range.select();
            }
        }
    }
    var inprogress = false;
    function FlagMessage() {
        if (inprogress) return;
        inprogress = true;
        $("#ajax").html("<img src=\"/Images/ajax-loader.gif\" width=32 height=32/>");
        $.ajax({
            type: "GET",
            cache: false,
            url: "/Game/MarkMessage",
            data: "messageID=<%=model.UID %>",
            success: function () {
                $("#redflag").html("<img src=\"/Images/Icons/flag_red.png\"  width=32 height=32/>");
                document.getElementById('redflag').onclick = function () { DeflagMessage(); };
                $("#ajax").html("");
                inprogress = false;
            },
            error: function () {
                $("#ajax").html("");
                inprogress = false;
            }
        });
    }
    function DeflagMessage() {
        if (inprogress) return;
        inprogress = true;
        $("#ajax").html("<img src=\"/Images/ajax-loader.gif\" width=32 height=32/>");
        $.ajax({
            type: "GET",
            cache: false,
            url: "/Game/MarkMessage",
            data: "messageID=<%=model.UID %>",
            success: function () {
                $("#redflag").html("<img src=\"/Images/Icons/flag_red_disabled.png\" width=32 height=32/>");
                document.getElementById('redflag').onclick = function () { FlagMessage(); };
                $("#ajax").html("");
                inprogress = false;
            },
            error: function () {
                $("#ajax").html("");
                inprogress = false;
            }
        });
    }
</script>
<div class="loading" style="position:absolute; top:8px; right:10px; width:156px; display:table-row;">
<%=Utils.CreateNavigationPanel(ViewData["Game"] as string, (Guid)ViewData["PrevGuid"], (Guid)ViewData["NextGuid"], model.UID) %>
</div>
<div id="ajax" class="loadblock" style="position:absolute; top:8px; right:-150px; width:156px;"></div>
<b><%=Utils.GetMessageSubjectColor(model) %></b><br /><br />
<%=Utils.GetColoredMessage(model.MessageText) %>
<br /><br /><br />
<% if (ViewData["UserData"] != null)
   { %>
   <form method="post" name="postmessage" action="/Game/PostMessage">
   <input type="hidden" name="game" value="<%=ViewData["Game"] %>" />
   <input type="hidden" name="nextguid" value="<%=ViewData["NextGuid"] %>" />
<span style="color:#039; font-weight:bold;">Адресат: <%=Utils.GetPossibleAdresseesDropDown(ViewData["Game"] as string, model)%></span><br /><br />
<textarea onfocus="setCursor(document.getElementById('msgtext'), 0, 0)" id="msgtext" name="msgtext" style="width:100%; height:160px; padding: 4px;"><%=Utils.GetQuotedText(Utils.GetStrippedText(str)) %>
</textarea>
<br />
<br />
<a href="#" class="awesome" onclick="document.postmessage.submit();return false;">Отправить</a>
<%--           <div class="button20" onclick="document.postmessage.submit();" style="float:left;">
                <div class="l"></div>
                <div class="m">Отправить</div>
                <div class="r"></div>
           </div>--%>
</form>
<% } %>
</asp:Content>
